package com.aaa.oauth.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

@Data
@TableName(value = "manager")
public class Manager implements UserDetails, Serializable {
    /**
     * 管理员id
     */
    @TableId(value = "mid", type = IdType.AUTO)
    private Integer mid;

    /**
     * 姓名
     */
    @TableField(value = "mname")
    private String mname;

    /**
     * 年龄
     */
    @TableField(value = "mage")
    private Integer mage;

    /**
     * 用户名
     */
    @TableField(value = "username")
    private String username;

    /**
     * 密码
     */
    @TableField(value = "password")
    private String password;

    /**
     * 管理员编号
     */
    @TableField(value = "mno")
    private Integer mno;

    /**
     * 状态
     */
    @TableField(value = "state")
    private Integer state;

    public static final String COL_MID = "mid";

    public static final String COL_MNAME = "mname";

    public static final String COL_MAGE = "mage";

    public static final String COL_USERNAME = "username";

    public static final String COL_PASSWORD = "password";

    public static final String COL_MNO = "mno";

    public static final String COL_STATE = "state";

    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;

    // 返回权限信息
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }


    // 账户是否过期:
    @Override
    public boolean isAccountNonExpired() {
        return this.state==1;
    }

    // 账户是否锁定
    @Override
    public boolean isAccountNonLocked() {
        return this.state==1;
    }

    // 凭证(密码)是否过期
    @Override
    public boolean isCredentialsNonExpired() {
        return this.state==1;
    }

    // 账户是否可用
    @Override
    public boolean isEnabled() {
        return this.state==1;
    }
}